--所谓荒野
local suoweihuangye = fk.CreateSkill {
    name = "mcdh_suoweihuangye",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

Fk:addPoxiMethod{
    name = "mcdh_suoweihuangye_getcard",
    card_filter = function(to_select, selected)
        return #selected ~= 1
    end,
    feasible = function(selected)
        return #selected == 1
    end,
    prompt = function ()
        return Fk:translate("#mcdh_suoweihuangye2")
    end
}

suoweihuangye:addEffect('active',{
    prompt ="#mcdh_suoweihuangye",
    card_num = 0,
    target_num = 0,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name) == 0 and #table.filter(Fk:currentRoom().alive_players, function (p) return (not p:isKongcheng())and p.id~=player.id end) > 0
    end,
    card_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = effect.from
        local targets = table.filter(room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
        local cardtem = {}
        local mincardshow=999
        local mincardplayer={}
        for _, p in ipairs(targets) do
            local pcards=room:askForCard(p,1,999,false,self.name,false,".","#mcdh_suoweihuangye1")
            table.insert(cardtem,{p.general,pcards})
            p:showCards(pcards)
            if #pcards<mincardshow then
                mincardshow=#pcards
                mincardplayer={}
                table.insert(mincardplayer,p)
            elseif #pcards==mincardshow then
                table.insert(mincardplayer,p)
            end
            room:delay(500)
        end
        local getcard = room:askForPoxi(player,"mcdh_suoweihuangye_getcard",cardtem,nil,false)
        local temcardowner = room:getCardOwner(getcard[1])
        if temcardowner then
            room:throwCard(getcard[1], self.name,temcardowner , player)
        end
        mincardplayer=table.filter(mincardplayer, function (p) return p:isAlive() and player:canUseTo(Fk:cloneCard("slash"),p,{ bypass_distances = true ,bypass_times = true}) end)
        if #mincardplayer > 0 then
            local slashplayer = room:askToChoosePlayers(player, {
                targets = mincardplayer,
                min_num = 1,
                max_num = 1,
                prompt = "#mcdh_suoweihuangye3",
                skill_name = self.name,
                cancelable = true
              })
            if #slashplayer > 0 then
                room:useVirtualCard("slash", nil, player, slashplayer, self.name, true)
            end
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_suoweihuangye"] = "荒野",
    [":mcdh_suoweihuangye"] = "『所谓荒野』<br>出牌阶段限一次，你可以令所有有手牌的其他角色依次展示至少一张手牌，你弃置其中一张展示牌，然后你可以选择一名展示了牌但展示牌数最少的一名角色，视为对其使用一张不计入次数且无次数限制的【杀】。",
    ["#mcdh_suoweihuangye"] = "令所有其他角色展示至少一张手牌，你弃置其中一张展示牌，然后你可以选择一名展示了牌但展示牌数最少的一名角色，视为对其使用一张【杀】。",
    ["#mcdh_suoweihuangye1"] = "所谓荒野：展示至少一张手牌，子月弃置所有展示牌中一张牌并可以对展示牌数最少的角色视为使用一张【杀】。",
    ["#mcdh_suoweihuangye2"] = "所谓荒野：弃置所有展示牌中一张牌。",
    ["#mcdh_suoweihuangye3"] = "所谓荒野：你可以对一名展示了牌但展示牌数最少的一名角色视为使用一张【杀】。",
    ["mcdh_suoweihuangye_getcard"] = "所谓荒野",
}

return suoweihuangye